<?php
include_once('inc/functions.inc.php');
?>
<!--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>admincuentas</title>
<link href="../css/conta.css" rel="stylesheet" type="text/css" />
<link href="../libs/jquery.ui/jquery.ui.css" rel="stylesheet" type="text/css" />
<link href="../libs/jquery.treeview/jquery.treeview.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/jquery.js" language="javascript"></script>
<script type="text/javascript" src="../libs/jquery.ui/jquery.ui.min.js" language="javascript"></script>
<script type="text/javascript" src="../libs/jquery.treeview/jquery.treeview.js" language="javascript"></script>
<script type="text/javascript" src="../../js/admin_conta.js" language="javascript"></script>
</head>-->
    <?php
    
    $empresa = getParam("empresa");
    
    $arrTMP = getContaHijas($db, $empresa, 0 );
    
    if( is_array($arrTMP) ) {
        ?>
        <div id="sidetreecontrol"><a href="#">Contraer Todo</a> | <a href="#">Expandir Todo</a></div>
        <ul class="treeview" id="tree" style="height: 100%;">
            <?php
                
            while ( $arrTMP1 = each($arrTMP) ) {
                
                if(  is_array($arrTMP1) && count($arrTMP1["value"]) > 0 ) {
                    
                    ?>
                    <li class='expandable'><div class='hitarea expandable-hitarea'></div><a href='#'><?php print $arrTMP1["key"]; ?></a><ul style='display: none;'>
                    <?php                    
                    while ( $arrTMP2 = each($arrTMP1["value"]) ) {
                       
                        if(  is_array($arrTMP2) && count($arrTMP2["value"]) > 0 ) {
                            
                            ?>
                            <li class='expandable'><div class='hitarea expandable-hitarea'></div><a href='#'><?php print $arrTMP2["key"]; ?></a><ul style='display: none;'>
                            <?php
                            while ( $arrTMP3 = each($arrTMP2["value"]) ) {
                       
                                if(  is_array($arrTMP3) && count($arrTMP3["value"]) > 0 ) {
                                    
                                    ?>
                                    <li class='expandable'><div class='hitarea expandable-hitarea'></div><a href='#'><?php print $arrTMP3["key"]; ?></a><ul style='display: none;'>
                                    <?php
                                    while ( $arrTMP4 = each($arrTMP3["value"]) ) {
                       
                                        if(  is_array($arrTMP4) && count($arrTMP4["value"]) > 0 ) {
                                            
                                            ?>
                                            <li class='expandable'><div class='hitarea expandable-hitarea'></div><a href='#'><?php print $arrTMP4["key"]; ?></a><ul style='display: none;'>
                                            <?php
                                            while ( $arrTMP5 = each($arrTMP4["value"]) ) {
                       
                                                if(  is_array($arrTMP5) && count($arrTMP5["value"]) > 0 ) {
                                                    
                                                    ?>
                                                    <li class='expandable'><div class='hitarea expandable-hitarea'></div><a href='#'><?php print $arrTMP5["key"]; ?></a><ul style='display: none;'>
                                                    <?php
                                                    while ( $arrTMP6 = each($arrTMP5["value"]) ) {                                          

                                                    }
                                                    ?>
                                                    </ul></li>
                                                    <?php
                                                    
                                                }
                                                else {
                                                    
                                                    ?>
                                                    <li><a href='#'><?php print $arrTMP5["key"]; ?></a></li>
                                                    <?php
                                                    
                                                }                                          

                                            }
                                            ?>
                                            </ul></li>
                                            <?php
                                            
                                        }
                                        else {
                                            
                                            ?>
                                            <li><a href='#'><?php print $arrTMP4["key"]; ?></a></li>
                                            <?php
                                            
                                        }                                                       
                                       
                                    }
                                    ?>
                                    </ul></li>
                                    <?php
                                    
                                }
                                else {
                                    
                                    ?>
                                    <li><a href='#'><?php print $arrTMP3["key"]; ?></a></li>
                                    <?php
                                    
                                }

                            }
                            ?>
                            </ul></li>
                            <?php
                            
                        }
                        else {
                            
                            ?>
                            <li><a href='#'><?php print $arrTMP2["key"]; ?></a></li>
                            <?php
                            
                        }
                       
                    }
                    ?>
                    </ul></li>
                    <?php 
                    
                }
                else {
                    ?>
                    <li><a href='#'><?php print $arrTMP1["key"]; ?></a></li>
                    <?php
                }

            }
        
            ?>
        </ul>
        <?php
    }
    ?>
    <script type="text/javascript" language="javascript">
    $("#tree").treeview({
        collapsed: false,
        animated: "fast",
        control:"#sidetreecontrol",
        prerendered: true,
        persist: "location"
    });
    </script>
<!--</body>
</html>-->
<?php
function getContaHijas($db, $empresa, $strPadre ) {

    $arrCuentas = array();
    //$empresa = getParam("empresa");
    $strQuery = "SELECT * FROM cllg_contab_cuenta WHERE fk_padre = '{$strPadre}' AND fk_empresa = '{$empresa}'";
    $qTMP = $db->query($strQuery);
    
    while ( $rTMP = $db->fetch_array($qTMP) ) {
        
        $arrCuentas[$rTMP["codigo"]." - ".$rTMP["nombre"]] = getContaHijas($db, $empresa, $rTMP["codigo"]);
        
    }
    $db->free_result($rTMP);
    
    return $arrCuentas;
    
}
?>